import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './plugins/element.js'
import axois from 'axios'
import axios from 'axios'

//导入nprogress来优化
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

// 基准路径
Vue.prototype.$http=axois
axois.defaults.baseURL='http://127.0.0.1:8888/api/private/v1/'

// 路由导航守卫
router.beforeEach((to,form,next)=>{
  if(to.path==="/login") return next()
  const tokenStr=localStorage.getItem('token')
  if(!tokenStr) return next('/login')
  next()
})

//路由拦截,添加token验证Authorization字段
axios.interceptors.request.use( config =>{
  NProgress.start()
  config.headers.Authorization=localStorage.getItem('token')
  console.log(config);
  return config
})
//NProgress
axios.interceptors.response.use( config =>{
  NProgress.done()
  console.log(config);
  return config
})

Vue.config.productionTip = false

//引入插件
import TreeTable from 'vue-table-with-tree-grid'
Vue.component('tree-table', TreeTable)

//引入富文本框插件
import VueQuillEditor from 'vue-quill-editor'
// require styles
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
Vue.use(VueQuillEditor)


//全局时间过滤器
Vue.filter('dateFormat',function(originVal){
  const dt=new Date(originVal)
  const y=dt.getFullYear()
  const m=(dt.getMonth()+1+'').padStart(2,'0')
  const d=(dt.getDate()+'').padStart(2,'0')
  const hh=(dt.getHours()+'').padStart(2,'0')
  const mm=(dt.getMinutes()+'').padStart(2,'0')
  const ss=(dt.getSeconds()+'').padStart(2,'0')
  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
